<?php 
    $url = new Url();
    $arrSubType = array();
    if($type == 1){
        $arrSubType = LoadConfig::$arrayTypeTransactionOut;
    }else if($type == 2){
            $arrSubType = LoadConfig::$arrayTypeTransactionIn;
        }
?>
<div class='left'>
    <?php
        $this->widget("AdminThanhvien");
    ?>
</div>
<div class="right-main">
    <div class="righ-cont">
        <div class="right">
            <div class="title_style"> <strong class="clred">Lịch sử giao dịch</strong></div>
            <div class="tool clearfix bottom15">
                <form name="search_form" method="get">
                    <ul class="form4">
                        <li class="clearfix">
                            <label><strong>Từ khóa :</strong></label>
                            <div class="filltext">
                                <input type="text" style="width:223px;margin-right:10px;" value="<?=$key_word?>" id="key_word" name="key_word" />
                            </div>
                        </li>
                        <li class="clearfix">
                            <label><strong>Thống kê :</strong> </label>
                            <div class="filltext">
                                <select style="width:235px;margin-right:21px;height: 24px;" name="type" id="type" onchange="loadSubType(this.value)">
                                    <option value="0">Tất cả</option>
                                    <option value="1" <?=$type==1?"selected='selected'":""?>>Tiêu tiền</option>
                                    <option value="2" <?=$type==2?"selected='selected'":""?>>Nạp tiền</option>
                                </select>
                            </div>
                        </li>
                        <li class="clearfix">
                            <label><strong>Hình thức :</strong> </label>
                            <div class="filltext">
                                <select style="width:235px;height: 24px;" name="sub_type" id="sub_type">
                                    <option value="0">Tất cả</option>
                                    <?php foreach($arrSubType as $key => $value){?>
                                        <option value="<?=$key?>" <?=$sub_type == $key ? "selected='selected'":""?>><?=$value?></option> 
                                        <?php }?>
                                </select>
                            </div>
                        </li>
                        <li class="clearfix">
                            <label><strong>Thời gian :</strong> </label>
                            <div class="filltext">

                                <?php        
                                    $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                                    'id'=>'from',
                                    'name'=>'from',
                                    'value'=>isset($fromDate)?$fromDate:date("d/m/Y",strtotime("-7 days")),
                                    'options'=>array(
                                    'showAnim'=>'fold',
                                    'dateFormat'=>'dd/mm/yy',
                                    ),
                                    'htmlOptions'=>array(
                                    'readonly'=>'readonly',
                                    ),
                                    ));                                     
                                ?>                                       

                                Đến 

                                <?php        
                                    $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                                    'id'=>'to',
                                    'name'=>'to',
                                    'value'=>isset($toDate)?$toDate:date("d/m/Y",time()),
                                    'options'=>array(
                                    'showAnim'=>'fold',
                                    'dateFormat'=>'dd/mm/yy',
                                    ),
                                    'htmlOptions'=>array(
                                    'readonly'=>'readonly',
                                    ),
                                    ));                                     
                                ?>                                       

                            </div>
                        </li>
                        <li class="clearfix">
                            <label>&nbsp; </label>
                            <div class="filltext">
                                <input type="submit" value="Tìm kiếm" class="button">
                            </div>
                        </li>
                    </ul>
                </form>
            </div>
            <hr />
            <div class="fillters clearfix">
                <ul class="paging fr">
                    <?=isset($page)?$page:""?>
                </ul>
            </div>
            <div class="table clearfix">

                <table cellspacing="0" cellpadding="0" border="0" width="100%">
                    <tbody>
                        <tr class="bg_gray">
                            <td width="7%"><strong>STT</strong></td>
                            <td width="22%"><strong>Tên user name</strong></td>
                            <td width="20%"><strong>Thời gian</strong></td>
                            <td width="18%"><strong>Số tiền<br />(+/-)</strong></td>
                            <td width="33%"><strong>Hình thức </strong></td>
                        </tr>
                        <?php foreach($data as $key => $value){
                           $time_int = strtotime($value['ngay']);?>
                        <tr>
                            <td><?=$key+1+$begin?></td>
                            <td><?=$value['user_name']?></td>
                            <td><?=date("d/m/Y",$time_int)?> <br/><?=date("H:i A",$time_int)?> </td>
                            <td>
                            <?php if(isset($value['nap_tien'])){?>
                            <span class="clblue">+ <?=$value['nap_tien']?> </span>
                            <?php }else if(isset($value['tru_tien'])){?>
                            <span class="clred">- <?=$value['tru_tien']?> </span> 
                            <?php }?>
                            </td>
                            <td class="text-left"><?=$value['content']?></td>
                        </tr>
                        <?php }?>
                    </tbody>
                </table>
            </div>
            <div class="fillters clearfix">
                <ul class="paging fr">
                    <?=isset($page)?$page:""?> 
                </ul>
            </div>
            <div class="clearfix">
                <table cellspacing="0" cellpadding="0" border="1" width="300px">
                    <tr>
                        <td>
                            <ul>
                                <li><strong class="s14">Tổng tiền nạp : <font color="blue"><?=$tong_nap;?></font></strong></li>
                                <li><strong class="s14">Tổng tiền tiêu : <font color="red"><?=$tong_tieu;?></font></strong></li>
                            </ul>
                        </td>
                    </tr>

                </table>
            </div>
        </div>
    </div>
</div>
<script>
    function loadSubType(type_id){       
        var strUrl = "<?=$url->createUrl('user/ajaxLoadSubType')?>";
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                type_id       :type_id
            },
            success: function(html){  
                $("#sub_type").html(html);                
            }
        });    
    }

</script>